package org.ws.task.repository;

import com.google.common.collect.Maps;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.ws.task.item.ExecuteContext;
import java.util.Map;

public class WorkerContextRepository {

    private static final WorkerContextRepository instance = new WorkerContextRepository();
    // Key:Map<TaskName,Context>
    private final Map<String, ExecuteContext> taskWorkerNodeContextMap;

    private WorkerContextRepository(){
        this.taskWorkerNodeContextMap = Maps.newHashMap();
    }

    public static WorkerContextRepository getInstance(){
        return instance;
    }

    public ExecuteContext getContext(String taskName){
        if(!this.taskWorkerNodeContextMap.containsKey(taskName)){
            this.taskWorkerNodeContextMap.put(taskName,new ExecuteContext());
        }
        return this.taskWorkerNodeContextMap.get(taskName);
    }

}
